<?php
/**
 * Created by PhpStorm.
 * User: *!N.J
 * Date: 2021/8/22
 * Time: 4:28
 * QQ:1467572213
 */

namespace app\hl\controller;

use think\facade\Request;
use think\facade\Session;
use \app\index\model\Account as Account_m;

class Account extends Base
{
    public function index()
    {
        $http = Request::domain();
        $invite_url = $http.'/ch/login/reg/invite_code/';
        $this->assign('invite_url',$invite_url);
        return $this->fetch();
    }

    public function aboutus()
    {
        return $this->fetch();
    }

    public function out()
    {
        Session::delete('user_id');
        return ['code'=>1,'msg'=>'Has exited safely'];
    }

    public function personal()
    {
        return $this->fetch();
    }

    public function card()
    {
        $user_id = Session::get('user_id');
        if (Request::isPost()){
            $info['bank_name'] = Request::post('bank_name');
            if (!$info['bank_name']) return ['code'=>0,'msg'=>'Banknaam mag niet leeg zijn'];
            $info['holder_name'] = Request::post('holder_name');

            if (!$info['holder_name'])return ['code'=>0,'msg'=>'Naam houder mag niet leeg zijn'];

            $info['account_number'] = Request::post('account_number');
            if (!$info['account_number']) return ['code'=>0,'msg'=>'Rekeningnummer mag niet leeg zijn'];

            $info['phone_number'] = Request::post('phone_number');
            if (!$info['phone_number']) return ['code'=>0,'msg'=>'Telefoonnummer mag niet leeg zijn'];

            $info['email'] = Request::post('email');
            if (!$info['email']) return ['code'=>0,'msg'=>'Mailbox mag niet leeg zijn'];

            $info['ifsc'] = Request::post('ifsc');
            if (!$info['ifsc']) return ['code'=>0,'msg'=>'IFSC mag niet leeg zijn'];

            $info['upi'] = Request::post('upi');
            if (!$info['upi'] ) return ['code'=>0,'msg'=>'UPI mag niet leeg zijn'];

            $info['update_time'] = time();
            $card = Account_m::card($user_id,$info);
            switch ($card)
            {
                case 'success':
                    return ['code'=>1,'msg'=>'Succes'];
                    break;
                case 'error':
                    return ['code'=>0,'msg'=>'Fout'];
                    break;
            }
        }
        return $this->fetch();
    }
    
    
     public function usdt(){

        $user_id = Session::get('user_id');
        if (Request::isPost()){
            $info['type'] = Request::post('type');
            if (!$info['type']) return ['code'=>0,'msg'=>'USDT-type mag niet leeg zijn'];
            
            $info['address_usdt'] = Request::post('address_usdt');
            if (!$info['address_usdt']) return ['code'=>0,'msg'=>'USDT-adres mag niet leeg zijn'];
            
            $info['phone_number'] = Request::post('phone_number');
            if (!$info['phone_number']) return ['code'=>0,'msg'=>'Telefoonnummer mag niet leeg zijn'];

            $info['email'] = Request::post('email');
            if (!$info['email']) return ['code'=>0,'msg'=>'E-mail mag niet leeg zijn'];

            $info['update_time'] = time();
            $card = Account_m::card($user_id,$info);
            switch ($card)
            {
                case 'success':
                    return ['code'=>1,'msg'=>'Success'];
                    break;
                case 'error':
                    return ['code'=>0,'msg'=>'Error'];
                    break;
            }
        }
        return $this->fetch();
    }

    public function invitation()
    {
        $user_id = Session::get('user_id');
        $user_info = \app\ch\model\Base::get_user_info($user_id);
        if (empty($user_info['qrcode'])){
            $qr_code = Account_m::create_qrcode($user_info['invite_code'],$user_id);
            $add_qr_code = Account_m::invitation($user_id,$qr_code);
            if ($add_qr_code == 'success'){
                $this->assign('qr_code',$qr_code);
            }
        }else{
            $this->assign('qr_code',$user_info['qrcode']);
        }
        $http = Request::domain();
        $invite_url = $http.'/ch/login/reg/invite_code/';
        $this->assign('invite_url',$invite_url);
        return $this->fetch();
    }

    public function message()
    {
        return $this->fetch();
    }

    public function address()
    {
        $user_id = Session::get('user_id');
        if (Request::isPost()){
            $info['address_name'] = Request::post('address_name');
            if (!$info['address_name']) return ['code'=>0,'msg'=>'Adresnaam mag niet leeg zijn'];

            $info['address_phone'] = Request::post('address_phone');
            if (!$info['address_phone']) return ['code'=>0,'msg'=>'Telefoonadres mag niet leeg zijn'];

            $info['address_info'] = Request::post('address_info');
            if (!$info['address_info']) return ['code'=>0,'msg'=>'Adresgegevens mogen niet leeg zijn'];
            $info['update_time'] = time();
            $address = Account_m::address($user_id,$info);
            switch ($address)
            {
                case 'success':
                    return ['code'=>1,'msg'=>'Succes'];
                    break;
                case 'error':
                    return ['code'=>0,'msg'=>'Fout'];
                    break;
            }
        }
        return $this->fetch();
    }

    public function invite_task()
    {
        return $this->fetch();
    }

    public function safe()
    {
        return $this->fetch();
    }

    public function password()
    {
        $user_id = Session::get('user_id');
        $user_info = \app\ch\model\Base::get_user_info($user_id);
        if (Request::isPost()){
            $o_pass = Request::post('o_pass');
            $n_pass = Request::post('n_pass');
            $c_pass = Request::post('c_pass');
            if ($n_pass != $c_pass){
                return ['code'=>0,'msg'=>'The two passwords are inconsistent'];
            }else{
                $set_password = Account_m::set_pass($user_info,$o_pass,$c_pass);
                switch ($set_password)
                {
                    case 'success':
                        return ['code'=>1,'msg'=>'Succes'];
                        break;
                    case 'error':
                        return ['code'=>0,'msg'=>'Fout'];
                        break;
                    case 'error_old':
                        return ['code'=>0,'msg'=>'Oorspronkelijke wachtwoordfout'];
                        break;
                }
            }
        }
        return $this->fetch();
    }

    public function password_pay()
    {
        $user_id = Session::get('user_id');
        $user_info = \app\ch\model\Base::get_user_info($user_id);
        if (Request::isPost()){
            $o_pass = Request::post('o_pass');
            $n_pass = Request::post('n_pass');
            $c_pass = Request::post('c_pass');
            if ($n_pass != $c_pass){
                return ['code'=>0,'msg'=>'De twee wachtwoorden zijn inconsistent'];
            }else{
                $set_password = Account_m::set_pass_pay($user_info,$o_pass,$c_pass);
                switch ($set_password)
                {
                    case 'success':
                        return ['code'=>1,'msg'=>'Succes'];
                        break;
                    case 'error':
                        return ['code'=>0,'msg'=>'Fout'];
                        break;
                    case 'error_old':
                        return ['code'=>0,'msg'=>'Oorspronkelijke wachtwoordfout'];
                        break;
                }
            }
        }
        return $this->fetch();
    }

    public function sms_code()
    {
        $user_id = Session::get('user_id');
        $user_info = \app\ch\model\Base::get_user_info($user_id);
        if (Request::isPost()){
            $type = Request::post('type');
            return ['code'=>1,'msg'=>$type];
            $send_sms = Account_m::sms_code($user_info['phone'],$type);
            switch ($send_sms)
            {
                case 'success':
                    return ['code'=>1,'msg'=>'Sent successfully'];
                    break;
                case 'error':
                    return ['code'=>0,'msg'=>'Fout'];
                    break;
            }
        }
    }

    public function freeze()
    {
        $user_id = Session::get('user_id');
        $user_info = \app\ch\model\Base::get_user_info($user_id);
        $freeze = Account_m::freeze($user_id);
        $this->assign('list',$freeze);
        return $this->fetch();
    }

    public function team()
    {
        $user_id = Session::get('user_id');
        $user_info = \app\ch\model\Base::get_user_info($user_id);
        $this->assign('user_info',$user_info);

        $team_data = Account_m::team_data($user_id);
        $this->assign('team_data',$team_data);

        $team_user = Account_m::team_user($user_id);
        $this->assign('team_user',$team_user);

        $level_info = Account_m::level_info();
        $this->assign('level_info',$level_info);
        return $this->fetch();
    }

}